/*
 * Copyright (c) 2006, 2021, webrx.cn All rights reserved.
 *
 */
package cn.webrx.example;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * <p>Project: javaseapp - Date01
 * <p>Powered by webrx On 2021-07-28 11:50:27
 * <p>Created by IntelliJ IDEA
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 16
 */
public class Date02 {
    public static void main(String[] args) throws ParseException {
        //使用Date 导入并实例化，java.util.Date
        Date d = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        System.out.println(sdf.format(d));
        System.out.println(d.getTime()); //返回一个时间戳

        long now = d.getTime() + (1000 * 60 * 60 * 24 * 10);
        d.setTime(now);
        System.out.println(sdf.format(d));

        //计算两个日期之间相关的天数
        Date birth = sdf.parse("2001-7-20 0:0:0");
        //将字符串解析转换为Date
        Date ddd = new Date();

        long days = (ddd.getTime() - birth.getTime())/1000/60/60/24;
        System.out.println(days);


        long nottime = System.currentTimeMillis();
    }
}
